package com.wzy.controller;

import com.wzy.pojo.ResidentialPass;

import com.wzy.service.ResidentialPassService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Controller
@RequestMapping(value="/residentialPass")
public class ResidentialPassController {
    @Autowired
    private ResidentialPassService residentialPassService;

    @RequestMapping
    public String findAllR(Model model){
        List<ResidentialPass> residentialPasses = residentialPassService.findAllResidentialPass();
        model.addAttribute("residentialPasses",residentialPasses);
        return "ResidentialPass";
    }
    @RequestMapping("/updateR")
    public String updateR(ResidentialPass residentialPass){
        residentialPassService.updateResidentialPass(residentialPass);
        System.out.println("updateSuccess");
        return "redirect:/residentialPass";
    }
    @RequestMapping("/deleteR")
    public String deleteR(String ID){
        residentialPassService.deleteResidentialPass(ID);
        return "redirect:/residentialPass";
    }
    @RequestMapping("addRPage")
    public String addRPage(){
        return "addResidentialPass";
    }

    @RequestMapping("addR")
    public String addR(ResidentialPass residentialPass,Model model) {
        if (residentialPassService.addResidentialPass(residentialPass)) {
            return "redirect:/residentialPass";
        } else {
            model.addAttribute("addResidentialPass", "该人以存在");
            return "addResidentialPass";
        }
    }
}
